//  Inside Microsoft Exchange 2007 Web Services 
//  Chapter 9
//
//  Copyright (c) 2007 David Sterling, Ben Spain, Mark Taylor, Huw Upshall, Michael Mainer.  
//  All rights reserved.
//
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using ProxyHelpers.EWS;

namespace SerializingTimeChangeTypeDemonstration
{
    class Program
    {
        static void Main(string[] args)
        {
            SerializingTimeChangeTypeDemonstration();
        }

        /// <summary>
        /// This method demonstrates serializing an instance of the
        /// TimeChangeType proxy type into XML.  The purpose is to 
        /// demonstrate the effect of XML serialization on the .Time
        /// property. (Listing 9-51)
        /// </summary>
        public static void SerializingTimeChangeTypeDemonstration()
        {
            RelativeYearlyRecurrencePatternType daylightTimeChangeDay =
                new RelativeYearlyRecurrencePatternType();
            daylightTimeChangeDay.DaysOfWeek =
                DayOfWeekType.Sunday.ToString();
            daylightTimeChangeDay.DayOfWeekIndex = DayOfWeekIndexType.Last;
            daylightTimeChangeDay.Month = MonthNamesType.October;

            TimeChangeType daylightTimeChange = new TimeChangeType();
            daylightTimeChange.TimeZoneName = "AUS Eastern Standard Time";
            daylightTimeChange.Offset = "-PT60M";
            daylightTimeChange.Item = daylightTimeChangeDay;

            // Define the time change DateTime instance as having a
            // DateTimeKind value of Unspecified.  The expected 
            // result here would be an xs:time string without a UTC
            // offset.
            //
            // Remember, the .Time field is a DateTime instance, but the 
            // 'date' portion really doesn't matter, just the time.
            //
            daylightTimeChange.Time =
             new DateTime(2007, 11, 28, 03, 00, 00, DateTimeKind.Unspecified);

            // Output to the console the results of serializing our 
            // TimeChangeType
            //
            System.Xml.Serialization.XmlSerializer mySerializer =
                new System.Xml.Serialization.XmlSerializer(
                    typeof(TimeChangeType));
            mySerializer.Serialize(System.Console.Out, daylightTimeChange);
        }

    }
}
